package com.fr.chart.legend;

import com.fr.base.DefaultValues;
import com.fr.base.FRContext;
import com.fr.base.FRFont;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.ChartModule;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.LegendGlyph;

public class Legend extends ChartModule
{
  private static final long serialVersionUID = 1L;
  public static final String XML_TAG = "Legend";
  private int position = 4;
  private FRFont frFont;
  private int maxShowLegendNumber = 10;
  private boolean legendVisible = true;
  private boolean autoAdjustSize = false;

  public Legend()
  {
    DefaultValues localDefaultValues = FRContext.getDefaultValues();
    this.frFont = localDefaultValues.getFRFont();
  }

  public int getPosition()
  {
    return this.position;
  }

  public void setPosition(int paramInt)
  {
    this.position = paramInt;
  }

  public FRFont getFRFont()
  {
    return this.frFont;
  }

  public void setFRFont(FRFont paramFRFont)
  {
    this.frFont = paramFRFont;
  }

  public void setMaxShowLegendNumber(int paramInt)
  {
    this.maxShowLegendNumber = paramInt;
  }

  public int getMaxShowLegendNumber()
  {
    return this.maxShowLegendNumber;
  }

  public void setLegendVisible(boolean paramBoolean)
  {
    this.legendVisible = paramBoolean;
  }

  public boolean isLegendVisible()
  {
    return this.legendVisible;
  }

  public LegendGlyph createLegendGlyph(LegendItem[] paramArrayOfLegendItem)
  {
    LegendGlyph localLegendGlyph;
    if (!(isLegendVisible()))
      return null;
    if (this.maxShowLegendNumber < paramArrayOfLegendItem.length)
    {
      LegendItem[] arrayOfLegendItem = new LegendItem[this.maxShowLegendNumber];
      for (int i = 0; i < this.maxShowLegendNumber; ++i)
        arrayOfLegendItem[i] = paramArrayOfLegendItem[i];
      localLegendGlyph = new LegendGlyph(arrayOfLegendItem);
    }
    else
    {
      localLegendGlyph = new LegendGlyph(paramArrayOfLegendItem);
    }
    localLegendGlyph.setFont(this.frFont);
    localLegendGlyph.setInfo(getInfo());
    localLegendGlyph.setPosition(this.position);
    localLegendGlyph.setAutoAdjustSize(this.autoAdjustSize);
    return localLegendGlyph;
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Legend localLegend = (Legend)super.clone();
    if (getFRFont() != null)
      localLegend.setFRFont((FRFont)getFRFont().clone());
    return localLegend;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    String str1;
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isAttr())
    {
      if ((str1 = paramXMLableReader.getAttr("position")) != null)
        setPosition(Integer.parseInt(str1));
      if ((str1 = paramXMLableReader.getAttr("legendNum")) != null)
      {
        int i = -1;
        try
        {
          int j = Integer.parseInt(str1);
          i = (j >= 0) ? j : -1;
        }
        catch (NumberFormatException localNumberFormatException1)
        {
        }
        setMaxShowLegendNumber(i);
      }
    }
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if (BaseXMLUtils.isFRFontTagName(str2))
        setFRFont(BaseXMLUtils.readFRFont(paramXMLableReader));
      if ("Attr".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("position")) != null)
          setPosition(Integer.parseInt(str1));
        if ((str1 = paramXMLableReader.getAttr("legendNum")) != null)
        {
          int k = -1;
          try
          {
            int l = Integer.parseInt(str1);
            k = (l >= 0) ? l : -1;
          }
          catch (NumberFormatException localNumberFormatException2)
          {
          }
          setMaxShowLegendNumber(k);
        }
        if ((str1 = paramXMLableReader.getAttr("visible")) != null)
          setLegendVisible(Boolean.valueOf(str1).booleanValue());
        if ((str1 = paramXMLableReader.getAttr("autoAdjustSize")) != null)
          setAutoAdjustSize(Boolean.valueOf(str1).booleanValue());
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Legend");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("position", getPosition()).attr("legendNum", getMaxShowLegendNumber()).attr("visible", this.legendVisible).attr("autoAdjustSize", this.autoAdjustSize).end();
    if (getFRFont() != null)
      BaseXMLUtils.writeFRFont(paramXMLPrintWriter, getFRFont());
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Legend))
      return false;
    Legend localLegend = (Legend)paramObject;
    if (!(super.equals(localLegend)))
      return false;
    if (localLegend.legendVisible != this.legendVisible)
      return false;
    if (localLegend.maxShowLegendNumber != this.maxShowLegendNumber)
      return false;
    if (localLegend.getPosition() != getPosition())
      return false;
    if (!(Equals.equals(localLegend.frFont, this.frFont)))
      return false;
    return (localLegend.autoAdjustSize == this.autoAdjustSize);
  }

  public void setAutoAdjustSize(boolean paramBoolean)
  {
    this.autoAdjustSize = paramBoolean;
  }

  public boolean isAutoAdjustSize()
  {
    return this.autoAdjustSize;
  }
}